package com.wsc.wisdomchina.activitity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.JsonTools;
import com.wsc.wisdomchina.Tools.Tools;
import com.wsc.wisdomchina.activitity.baseactivity.BaseActivity;
import com.wsc.wisdomchina.callback.ContributorView;
import com.wsc.wisdomchina.javaBean.RespObj;
import com.wsc.wisdomchina.presenter.ContributorPresenter;
import com.wsc.wisdomchina.view.MyToast;


public class ShouliCenterCancelActivity extends BaseActivity implements View.OnClickListener, ContributorView {

    private ImageView regist_back;
    private TextView tv_headtitle;
    private int state;
    private TextView tv_name;
    private TextView tv_time;
    private String title;
    private long time;
    private long finishTime;
    private String id;
    private RelativeLayout layout_shenhefinish;
    private TextView tv_timefinish;
    private TextView tv_timesbumit;
    private TextView tv_namefinish;
    private ContributorPresenter contributorPresenter;
    private Context context;
    private final String UPDATESERVERBYIDFLAG = "UPDATESERVERBYIDFLAG";
    private MyToast myToast;
    private String remarks;
    private Button mBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shoulicentercancel_layout);
        initView();
        Intent intent = getIntent();
        context = this;
        myToast = new MyToast(context);
        contributorPresenter = new ContributorPresenter(this, context);
        state = intent.getIntExtra("state", 0);
        title = intent.getStringExtra("title");
        time = intent.getLongExtra("time", 0);
        finishTime = intent.getLongExtra("finishTime", 0);
        id = intent.getStringExtra("id");
        remarks = intent.getStringExtra("remarks");
        tv_namefinish.setText(title);
        tv_timesbumit.setText(Tools.timedateyyyy_MM_dd(String.valueOf(time / 1000)));
        if (finishTime != 0) {
            tv_timefinish.setText(Tools.timedateyyyy_MM_dd(String.valueOf(finishTime / 1000)));
        }
    }

    private void initView() {
        regist_back = (ImageView) findViewById(R.id.regist_back);
        regist_back.setOnClickListener(this);
        tv_headtitle = (TextView) findViewById(R.id.tv_headtitle);
        tv_headtitle.setText("业务详情");
        tv_headtitle.requestFocus();
        tv_headtitle.setFocusable(true);
        tv_headtitle.setFocusableInTouchMode(true);
        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_time = (TextView) findViewById(R.id.tv_time);
        layout_shenhefinish = (RelativeLayout) findViewById(R.id.layout_shenhefinish);

        tv_timefinish = (TextView) findViewById(R.id.tv_timefinish);
        tv_timesbumit = (TextView) findViewById(R.id.tv_timesbumit);
        tv_namefinish = (TextView) findViewById(R.id.tv_namefinish);

        mBack = (Button) findViewById(R.id.bt_back);
        mBack.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.regist_back:
                finish();
                break;
            case R.id.bt_back:
                finish();
                break;
        }
    }

    @Override
    public void onLoadContributorStart(String flag) {

    }


    @Override
    public void onLoadContributorSuccess(String jsonString, String flag) {
        try {
            if (flag.equals(UPDATESERVERBYIDFLAG)) {
                RespObj respObj = JsonTools.jsonStringToObject(jsonString, RespObj.class);
                String code = respObj.getCode();
                Object object = respObj.getMessage();
                if (code.equals("200") && object != null) {
                    String jsonMessage = (String) object;
                    if (jsonMessage.equals("41")) {
                        myToast.showShort("评价成功");
                        finish();
                    } else {
                        myToast.showShort("评价失败");
                    }
                } else {
                    myToast.showShort("评价失败");
                }
            }

        } catch (Exception e) {

        }
    }


    @Override
    public void onLoadContributorComplete(String flag) {
    }

    @Override
    public void onLoadContributorError(String error, String flag) {
    }
}
